import { getToken, setToken, removeToken } from "@/utils/auth";
import { login, getInfo } from "@/api/user";
const state = {
  Token: getToken(),
  userInfo: {},
};
// const getters = {
//   userInfo: (state) => {
//     return JSON.parse(JSON.stringify(state.userInfo));
//   },
// };
const mutations = {
  setToken(state, Token) {
    state.Token = Token;
    setToken(Token);
  },
  // 删除token
  removeToken(Token) {
    Token.Token = null;
    removeToken(Token);
  },
  // 删除个人信息
  userInfo(state, userinfo) {
    state.userinfo = userinfo;
  },
};
const actions = {
  async loginToken(context, data) {
    const token = await login(data);
    context.commit("setToken", token);
    return state.userinfo;
  },
  async getuserInfo(context, datainfo) {
    console.log(111);
    const data = await getInfo();
    context.commit("userInfo", data);

    console.log(data);
  },
  // 退出登录
  async loginout(context) {
    console.log(123323);
    await context.commit("removeToken");
    await context.commit("userInfo", {});
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  // getters,
};
